<?php

namespace Action\Contact;

class AllDialog extends \Library\Action\UserAction 
	implements \Library\Action\AjaxAction {
	
	private $_user;
	private $_contacts;

	public function execute() {
		parent::execute();
		
		$user_id = (int) $this->getParam( 'id' );
		$this->_user = \Bean\User::get( $user_id );
		
		return array(
			'content' => $this->view(),
			'fullname' => $this->_user->getFullName()
		);
	}
	
	public function getUser() {
		return $this->_user;
	}
	
	public function getContacts() {
		if( $this->_contacts === null ) {
			$contacts = _q()->getN( 'users_contacts', array( 'user_id' => $this->getUser()->getUserId() ) );
			$this->_contacts = array();
			foreach( $contacts as $contact ) {
				$this->_contacts[] = new \Library\Widget\Result\UserResult( \Bean\User::get( $contact['contact_id'] ) );
			}
		}
		return $this->_contacts;
	}
}
